﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title></title>
    <style>
        #result {
            width: 200px;
            height: 100px;
            border: solid 1px #90b;
        }
    </style>
    <script crossorigin="anonymous" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
</head>
<body>
    用户名：<input type="text" id="username"/>
    <p></p>
    <script>
        const input = document.querySelector('input');
        const p = document.querySelector('p');
        //声明handle函数
        function handle(data) {
            input.style.border = 'solid 1px #f00';
            p.innerHTML = data.msg;
        }
        input.onblur = function () {
            //获取用户的输入值
            let username = this.value;
            //向服务器端发送请求，检测用户名示符存在
            //1、创建script标签
            const script = document.createElement('script');
            //2、设置标签的src属性
            script.src = 'http://127.0.0.1:8000/check-username';
            //3、将script插入到文档中
            document.body.appendChild(script);

        }

    </script>
</body>
</html>